<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="<%=basePath%>Js/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/mycss/bootstrap.min.css" />

<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
		<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
		<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<script type="text/javascript">

//修改会员基本信息
function alterVipInf(){
	
	var vipNumber = $("#vipNumber").val();
	var vipName = $("#vipName").val();
	var vipGender = $("#vipGender").val();
	var vipAge = $("#vipAge").val();
	var vipIdNumber = $("#vipIdNumber").val();
	var vipAddress = $("#vipAddress").val();
	var vipPhone = $("#vipPhone").val();
	
	if(confirm("是否确定修改")){
	$.ajax({
		type:"post",
		url:"updateVip.do",
		data:{
			"vipNumber":vipNumber,
			"vipName":vipName,
			"vipgender":vipGender,
			"vipage":vipAge,
			"vipidnumber":vipIdNumber,
			"vipaddress":vipAddress,
			"vipphone":vipPhone,
		},
		dataType:"text",
		success:function(result){
			if(result == "1"){
				alert("修改成功")
			}else{
				alert("修改失败")
			}
		},
		error:function(result){
			alert("系统故障")
		}
	})
	}
}

//修改密码
function changePassword(){
	
	var fristpassword = $("#fristpassword").val();
	var endpassword = $("#endpassword").val();
	var password1 = $("#password").val();
	var originalpassword = $("#originalpassword").val();
	if(password1 != originalpassword){
		alert("原密码错误")
	}else{
		if(fristpassword == endpassword){
			if(confirm("是否确定修改密码")){
				$.ajax({
					type:"post",
					url:"changePassword.do",
					data:{
						"passWord":endpassword,
						"password1":password1,
					},
					dataType:"text",
					success:function(result){
						if(result == "1"){
							
							alert("密码修改成功")
							window.location.href="selectvipBysession.do"
						}else{
							alert("密码修改失败")
							
						}
					},
					error:function(){
						alert("系统故障")
					}
				})
			}
			
		}else{
			alert("前后密码不一致")
		}	
	}
		
		
}

//会员充值
function vipTopup(){
	var topup = $("#topup").val();
	if (!(/(^[0-9]*[1-9][0-9]*$)/.test(topup))){
		alert("请输入整数");
	}else{
		
		if(confirm("是否确定充值")){
			$.ajax({
				type:"post",
				url:"vipTopup.do",
				data:{
					"topup":topup,
				},
				dataType:"text",
				success:function(result){
					if(result == "1"){
						
						alert("充值成功")
						window.location.href="selectvipBysession.do"
					}else{
						alert("充值失败")
						
					}
				},
				error:function(){
					alert("系统故障")
				}
			})
		}
		
	}
	
}


</script>

<body>

<hr><h3 align="center">修改会员信息</h3><hr>


	<div id="mydiv" style="position: absolute; left: 300px; top: 100px; width: 700px; height: 50px">

		<table class="table table-bordered">
			<tr>
				<td>会员卡号</td>
				<td><input type="text" class="form-control" id="vipNumber"
					value="${client.number}" disabled='disabled'></td>
				<td>姓名</td>
				<td><input type="text" class="form-control" id="vipName"
					value="${client.name}"></td>
			</tr>
			<tr>
				<td>性别</td>
				<td><input type="text" class="form-control" id="vipGender"
					value="${client.gender}"></td>
				<td>年龄</td>
				<td><input type="text" class="form-control" id="vipAge"
					value="${client.age}"></td>
			</tr>
			<tr>
				<td>出生年月</td>
				<td><input type="text" class="form-control" id="vipBrith"
					value="${client.reserved3}"></td>
				<td>会员等级</td>
				<td><input type="text" class="form-control" id="vipGrade"
					value="${client.grade}" disabled='disabled'></td>
			</tr>
			<tr>
				<td>身份证号</td>
				<td><input type="text" class="form-control" id="vipIdNumber"
					value="${client.idnumber}"></td>
				<td>居住地址</td>
				<td><input type="text" class="form-control" id="vipAddress"
					value="${client.address}"></td>
			</tr>
			<tr>
				<td>余额</td>
				<td>${client.money}￥<input type="text" id="topup">
				<button type="button" onclick="vipTopup()">充值</button>	
				</td>
				<td>密码</td>
				<td><a href="" data-toggle="modal" data-target="#myModal">密码修改</a></td>
			</tr>
			<tr>
				<td>电话号码</td>
				<td><input type="text" class="form-control" id="vipPhone"
					value="${client.phone}"></td>
				<td></td>
				<td><button onclick="alterVipInf()" type="button"
						class="btn btn-success">修改信息</button></td>
			</tr>
		</table>
	</div>

	
	<!-- 模态框（Modal） -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							&times;
						</button>
						<h3 class="modal-title" id="myModalLabel" align="center">
							密码修改
						</h3>
					</div>
					<div class="modal-body" id="Inf">
						<table class="table table-bordered">
			<tr>
				<td>当前密码</td>
				<td><input type="text" class="form-control" id="password">
				<input type="hidden" id="originalpassword" value="${sessionScope.viplogin.password}">	 
			    </td>
			</tr>
			<tr>
				<td>修改密码</td>
				<td><input type="text" class="form-control" id="fristpassword"></td>
			</tr>
			<tr>
				<td>确认密码</td>
				<td><input type="text" class="form-control" id="endpassword"></td>
			</tr>
			<tr>
				<td></td>
				<td><button onclick="changePassword()" type="button"
						class="btn btn-success">修改密码</button></td>
			</tr>
		</table>
					</div>
					<div class="modal-footer" id="xiugai">
					
					</div>
				</div><!-- /.modal-content -->
			</div><!-- /.modal -->
		</div>
	
	

</body>
</html>